<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/5/27
 * Time: 12:10
 */

namespace app\admin\controller;


use app\admin\logic\BusBrandLogic;
use app\admin\logic\BusBusinessLogic;
use app\admin\logic\BusLogic;
use think\facade\Request;

class Bus extends Base
{

    private $busLogic;

    public function __construct()
    {
        parent::__construct();
        $this->busLogic = new BusLogic();
    }

    public function index(){
        $businessLogic = new BusBusinessLogic();
        $businessList = $businessLogic->getAllBusiness();
        $this->assign('business', $businessList['data']);
        return $this->fetch();
    }

    public function ajaxIndex(){
        $tempWhere = Request::param();
        $busList = $this->busLogic->busList($tempWhere, self::$nowPage);
        return json($busList);
    }

    public function add(){
        $act = 'add';
        $id = Request::get('id');
        if ($id){
            $act = 'edit';
            $busInfo = $this->busLogic->info($id);
            $this->assign('info', $busInfo['data']['bus_info']);
            $this->assign('img_str', $busInfo['data']['img_str']);
        }
        $brandLogic = new BusBrandLogic();
        $brandList = $brandLogic->getAllBrand();
        $businessLogic = new BusBusinessLogic();
        $businessList = $businessLogic->getAllBusiness();
        $this->assign('business', $businessList['data']);
        $this->assign('brand_list', $brandList['data']);
        $this->assign('act', $act);
        return $this->fetch();
    }

    /**
     * 处理车辆添加逻辑
     * @return \think\response\Json
     */
    public function handle(){
        $data = Request::param();
        $res = $this->busLogic->handle($data);
        return json($res);
    }

    public function getBus(){
        $tempWhere = Request::param('');
        $tempWhere['state'] = 2;
        $busList = $this->busLogic->getBus($tempWhere);
        return json($busList);
    }

    /**
     * 车辆审核列表
     * @return \think\response\View
     */
    public function stateIndex(){
        $businessLogic = new BusBusinessLogic();
        $businessList = $businessLogic->getAllBusiness();
        $this->assign('business', $businessList['data']);
        return view();
    }

    /**
     * 车辆审核异步列表
     */
    public function stateAjax(){
        $tempWhere = Request::post();
        $tempWhere['state'] = 1;
        $res = $this->busLogic->busList($tempWhere, self::$nowPage);
        return json($res);
    }

    /**
     * 车辆审核详情
     */
    public function stateInfo(){
        $act = 'state';
        $id = Request::get('id');
        if ($id){
            $busInfo = $this->busLogic->info($id);
            $this->assign('info', $busInfo['data']['bus_info']);
            $this->assign('img_str', $busInfo['data']['img_str']);
        }
        $brandLogic = new BusBrandLogic();
        $brandList = $brandLogic->getAllBrand();
        $businessLogic = new BusBusinessLogic();
        $businessList = $businessLogic->getAllBusiness();
        $this->assign('business', $businessList['data']);
        $this->assign('brand_list', $brandList['data']);
        $this->assign('act', $act);
        return view();
    }

}